package com.pinyoumei.app.activity.wallet;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.pinyoumei.app.R;
import com.pinyoumei.app.view.WithDrawKeyboard;

import java.util.List;

public class WalletRechargeAdapter extends BaseAdapter {

    private Context context;
    private List<WalletRechargeBean> datas;

    public WalletRechargeAdapter(Context context,List<WalletRechargeBean> datas){
        this.context = context;
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (viewHolder == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.wallet_recharge_grid_item, parent, false);
            viewHolder = new ViewHolder(convertView);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }
        WalletRechargeBean bean = datas.get(position);
        viewHolder.wrgiItemTxt.setText(bean.getMoneyNum()+"元");
        if (bean.isSelect()){
            viewHolder.wrgiItemTxt.setBackgroundResource(R.mipmap.wallet_select_icon);
        }else{
            viewHolder.wrgiItemTxt.setBackgroundResource(R.drawable.radius6_color_ffffff_bg);
        }

        return convertView;
    }

    /**
     * ViewHolder,view缓存
     */
    static class ViewHolder {
        private TextView wrgiItemTxt;

        public ViewHolder(View view) {
            wrgiItemTxt = view.findViewById(R.id.wrgi_item_txt);
        }
    }
}
